//
//  TravelInforViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/9.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "TravelInforViewController.h"
#import "CustomMadeCell.h"
#import "VsitorCommentCell.h"
#import "CDZStarsControl.h"
#import "VsitorCommentCell.h"
#import "TravelLikeButton.h"
#import <WebKit/WebKit.h>
#import "TravelInforModel.h"
#import "CustomMadeModel.h"
#import "VisitorCommentModel.h"
#import "AdModel.h"
#import "ImmediateEvaluationViewController.h"
#import "VisitorCommentCellModel.h"
#import "MoreCommentViewController.h"
#import "XXTripTableViewController.h"
#import "HomeViewController.h"
#import "MyJourneyViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import "HotViewController.h"
#import "BookingInformationViewController.h"
#define headImageH 200
#define border 10
#define labelH 20
#define locationBtnW 200
#define bottomBarH 50
#define sectionH 80
#define moreInforBtnW 100
@interface TravelInforViewController ()<UITableViewDelegate, UITableViewDataSource, CDZStarsControlDelegate, WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * headerView;
@property (nonatomic, strong)UIView * footerView;
@property (nonatomic, strong)UILabel * inforTitleLab;
@property (nonatomic, strong)UIImageView * headImage;
@property (nonatomic, strong)UILabel * priceLab;
@property (nonatomic, strong)UIView * starsView;
@property (nonatomic, strong)UILabel * scoreLab;
@property (nonatomic, strong)UILabel * commentsLab;
@property (nonatomic, strong)UIImageView * locationImage;
@property (nonatomic, strong)UILabel * locationLab;
@property (nonatomic, strong)UIButton * phoneBtn;
@property (nonatomic, strong)UIImageView * videoImage;
@property (nonatomic, strong)CDZStarsControl *starsControl;
@property (nonatomic, strong)UIButton * moreCommentBtn;//点击查看更多评论
@property (nonatomic, strong)UIButton * wantCommentBtn;//我要评论
@property (nonatomic, strong)UIImageView * adImage;
@property (nonatomic, strong)UIView * bottomBarView;
@property (nonatomic, strong)UIButton * moreInforBtn;//更多图文详情
@property (nonatomic, strong)UIButton * collectBtn;
@property (nonatomic, strong)UIButton * serviceBtn;
@property (nonatomic, strong)UIButton * addTravelBtn;
@property (nonatomic, strong)WKWebView * moreInforWeb;
@property (nonatomic, assign)int webH;//web页的高度
@property (nonatomic, strong)TravelInforModel * travelInforModel;
@property (nonatomic, strong)CustomMadeModel * customMadeModel;
@property (nonatomic, strong)AdModel * adModel;
@property (nonatomic, strong)VisitorCommentCellModel * cellModel;
@property (nonatomic, assign)int comments;//还剩多少条评论
@property (nonatomic, assign)int timeSign;
@property (nonatomic, assign)NSString * cityStr;
@property (nonatomic, strong)UIViewController * lastVC;
@property (nonatomic, strong)NSString * praviteOrderProjectID;//私人订制项目ID
@end

@implementation TravelInforViewController(Networking)
- (void)travelInforLikeBtnClick{
    NSDictionary * dic = @{
                           @"tid":@(self.tid),
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"type":@(1)
                           };
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/collect") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)travelInforData{
    NSDictionary * dic = @{
                           @"tid":@(self.tid),
                           @"mid":[UserModel intance].member_id
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/travelDetail") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.travelInforModel = [TravelInforModel yy_modelWithDictionary:obj[@"data"]];

                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)privateOrderData{
    NSDictionary * dic = @{
                           @"tid":@(self.tid)
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/package") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.customMadeModel = [CustomMadeModel yy_modelWithDictionary:obj];
                
                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)getCommentData{
    NSDictionary * dic = @{
                           @"tid":@(self.tid),
                           @"page":@(1),
                           @"row":@(2)
                           };
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/evaluate") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.cellModel = [VisitorCommentCellModel yy_modelWithDictionary:obj];
                
                [self.tableView reloadData];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

- (void)adPicData{
    WS(ws)
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/detailBottom") andParas:nil andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            //            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                ws.adModel = [AdModel yy_modelWithDictionary:obj[@"data"]];
                [self.adImage sd_setImageWithURL:[NSURL URLWithString:self.adModel.pic]];
            }else{
                //                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}
//
- (void)submitJourneyData{
    NSDictionary * dic = @{
                           @"trip_id":@([self.trip_id intValue]),
                           @"token":[UserModel intance].token,
                           @"mid":[UserModel intance].member_id
                           };
    [self showprogressHUD];
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/TripDetail") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self hiddenProgressHUD];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){

            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

//加一天行程
- (void)addNewJourney{
    NSDictionary * dic = @{
                           @"trip_id":@([self.trip_id intValue]),
                           @"token":[UserModel intance].token,
                           @"mid":[UserModel intance].member_id,
                           @"tid":@(self.tid),
                           @"day":@(self.travelDays)
                           };
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/index/addOneday") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
                XXTripTableViewController * vc = [[XXTripTableViewController alloc] init];
                vc.trip_id = [self.trip_id intValue];
                vc.tid = self.tid;
//                vc.title = [NSString stringWithFormat:@"%@行程",self.cityStr];
                vc.travelDays = self.travelDays;
                vc.selectTravelDays = self.selectTravelDays;
                [self.navigationController pushViewController:vc animated:YES];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}

@end

@implementation TravelInforViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomBarView];
    self.navigationController.delegate = self;
    NSLog(@"旅游信息");
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self privateOrderData];
    [self getCommentData];
    [self adPicData];
    
    NSArray *vcsArray = [self.navigationController viewControllers];
    NSInteger vcCount = vcsArray.count;
    _lastVC = vcsArray[vcCount-2];
    
    if ([_lastVC isKindOfClass:[HomeViewController class]]) {
        self.travelDays = 1;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.navigationController.delegate == nil)
    {
        self.navigationController.delegate = self;
    }
    [self travelInforData];
//    [self.tableView reloadData];
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - bottomBarH);
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.footerView;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }return _tableView;
}

- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] init];
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 600);
        UIButton *back = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 30, 30)];
        [back setImage:[UIImage imageNamed:@"icon_back2lwx"] forState:UIControlStateNormal];
        [back addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [_headerView addSubview:self.headImage];
        [_headerView addSubview:back];
        [_headerView addSubview:self.inforTitleLab];
        [_headerView addSubview:self.priceLab];
        [_headerView addSubview:self.scoreLab];
        [_headerView addSubview:self.commentsLab];
        [_headerView addSubview:self.locationImage];
        [_headerView addSubview:self.locationLab];
        [_headerView addSubview:self.phoneBtn];
        [_headerView addSubview:self.videoImage];
        [_headerView addSubview:self.starsControl];
        self.headImage.frame = CGRectMake(0, 0, SCREEN_WIDTH, 200);
        self.inforTitleLab.frame = CGRectMake(border, self.headImage.bottom, SCREEN_WIDTH - 2 * border, labelH);
        self.priceLab.frame = CGRectMake(self.inforTitleLab.left, self.inforTitleLab.bottom, 200, labelH);
        self.starsControl.frame = CGRectMake(self.inforTitleLab.left, self.priceLab.bottom, 80, labelH);
        self.scoreLab.frame = CGRectMake(self.starsControl.right + border, self.priceLab.bottom, 40, labelH);
        self.commentsLab.frame = CGRectMake(self.scoreLab.right, self.scoreLab.top, 100, labelH);
        self.phoneBtn.frame = CGRectMake(SCREEN_WIDTH - border - labelH, self.commentsLab.bottom, labelH, labelH);
        self.locationImage.frame = CGRectMake(self.inforTitleLab.left, self.commentsLab.bottom, border, labelH - 8);
        self.locationLab.frame = CGRectMake(self.locationImage.right, self.commentsLab.bottom, SCREEN_WIDTH - self.phoneBtn.width - labelH - self.locationImage.right, labelH);
        self.locationImage.centerY = self.locationLab.centerY;

        //分割线以下
        UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.locationLab.bottom + border, SCREEN_WIDTH, 1)];
        lineView.backgroundColor = getColor(bgColor);
        [_headerView addSubview:lineView];
        
        UILabel * displayLab = [[UILabel alloc] init];
        displayLab.frame = CGRectMake(0, lineView.bottom, SCREEN_WIDTH, labelH);
//        displayLab.text = @"场景展示";
        displayLab.font = DEF_FontSize_12;
        displayLab.textAlignment = NSTextAlignmentCenter;
        [_headerView addSubview:displayLab];
        
        self.videoImage.frame = CGRectMake(border, displayLab.bottom, SCREEN_WIDTH - 2 * border, headImageH);
        UIButton * videoBtn = [[UIButton alloc] initWithFrame:self.videoImage.frame];
        [videoBtn addTarget:self action:@selector(videoBtnClick) forControlEvents:UIControlEventTouchUpInside];
        videoBtn.backgroundColor = [UIColor clearColor];
        [_headerView addSubview:videoBtn];
        
        self.moreInforWeb.frame = CGRectMake(self.videoImage.left, self.videoImage.bottom + border, self.videoImage.width, 0);
         [_headerView addSubview:self.moreInforWeb];
        
        
        
        
        
        //        首先是关键JS代码：
        NSString *jScript =
        @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta); var imgs = document.getElementsByTagName('img');for (var i in imgs){imgs[i].style.maxWidth='100%';imgs[i].style.height='auto';}"
        ;
        //        然后初始化并加入JS片段：
        WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        WKUserContentController *wkUController = [[WKUserContentController alloc] init];
        [wkUController addUserScript:wkUScript];
        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        wkWebConfig.userContentController = wkUController;
        self.moreInforWeb = [[WKWebView alloc] initWithFrame:CGRectMake(self.videoImage.left, self.videoImage.bottom + border, self.videoImage.width, 0) configuration:wkWebConfig];
        self.moreInforWeb.scrollView.bounces = NO;
        self.moreInforWeb.scrollView.showsHorizontalScrollIndicator = NO;
        self.moreInforWeb.scrollView.scrollEnabled = NO;
        self.moreInforWeb.navigationDelegate = self;
        [_headerView addSubview:self.moreInforWeb];
        
        
        
        
        
        self.moreInforBtn.frame = CGRectMake((SCREEN_WIDTH - moreInforBtnW) / 2, self.moreInforWeb.bottom + border, moreInforBtnW, labelH);
        [_headerView addSubview:self.moreInforBtn];
        
        _headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, _moreInforBtn.bottom + border);
    }return _headerView;
}

- (UIButton *)moreInforBtn{
    if (!_moreInforBtn) {
        _moreInforBtn = [[UIButton alloc] init];
        [_moreInforBtn setCornerRadius:6];
        _moreInforBtn.titleLabel.font = DEF_FontSize_13;
        _moreInforBtn.layer.borderColor = [UIColor orangeColor].CGColor;
        _moreInforBtn.layer.borderWidth = 1;
        [_moreInforBtn setTitle:@"更多图文详情" forState:UIControlStateNormal];
        [_moreInforBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [_moreInforBtn addTarget:self action:@selector(moreInforBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }return _moreInforBtn;
}

- (UIImageView *)headImage{
    if (!_headImage) {
        _headImage = [[UIImageView alloc] init];
        _headImage.image = [UIImage imageNamed:@"img_list2111"];
    }return _headImage;
}

- (UILabel *)inforTitleLab{
    if (!_inforTitleLab) {
        _inforTitleLab = [[UILabel alloc] init];
//        _inforTitleLab.text = @"儿童而特t";
        _inforTitleLab.font = DEF_FontSize_14;
    }return _inforTitleLab;
}

- (UILabel *)priceLab{
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] init];
//        _priceLab.text = @"￥34235.00/人均";
        _priceLab.textColor = [UIColor grayColor];
        _priceLab.font = DEF_FontSize_12;
    }return _priceLab;
}

- (UILabel *)scoreLab{
    if (!_scoreLab) {
        _scoreLab = [[UILabel alloc] init];
//        _scoreLab.text = @"1.6分";
        _scoreLab.font = DEF_FontSize_12;
    }return _scoreLab;
}

- (UILabel *)commentsLab{
    if (!_commentsLab) {
        _commentsLab = [[UILabel alloc] init];
//        _commentsLab.text = @"（5条评价）";
        _commentsLab.font = DEF_FontSize_12;
    }return _commentsLab;
}

- (UIImageView *)locationImage{
    if (!_locationImage) {
        _locationImage = [[UIImageView alloc] init];
        _locationImage.image = [UIImage imageNamed:@"xc_locationlwx"];
    }return _locationImage;
}

- (UILabel *)locationLab{
    if (!_locationLab) {
        _locationLab = [[UILabel alloc] init];
        _locationLab.font = DEF_FontSize_12;
        _locationLab.textAlignment = NSTextAlignmentLeft;
//        _locationLab.text = @"北京市北京市 市辖区东城区 34545";
    }return _locationLab;
}

- (UIButton *)phoneBtn{
    if (!_phoneBtn) {
        _phoneBtn = [[UIButton alloc] init];
        [_phoneBtn setImage:[UIImage imageNamed:@"WechatIMG14"] forState:UIControlStateNormal];
        [_phoneBtn addTarget:self action:@selector(phoneBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _phoneBtn;
}

- (UIImageView *)videoImage{
    if (!_videoImage) {
        _videoImage = [[UIImageView alloc] init];
        _videoImage.image = [UIImage imageNamed:@"img_list2111"];
    }return _videoImage;
}

- (CDZStarsControl *)starsControl{
    if (!_starsControl) {
        _starsControl = [CDZStarsControl.alloc initWithFrame:CGRectMake(border, 100, 200 , 30) stars:5 starSize:CGSizeMake(15, 15) noramlStarImage:[UIImage imageNamed:@"icon-bigstar_grey"] highlightedStarImage:[UIImage imageNamed:@"icon-bigstar_yellow"]];
        _starsControl.delegate = self;
        _starsControl.allowFraction = YES;
        _starsControl.score = 1.6f;
        [_starsControl setUserInteractionEnabled:NO];
    }
    return _starsControl;
}

- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] init];
//        _footerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 60);
        self.adImage = [[UIImageView alloc] init];
        self.adImage.frame = CGRectMake(border, border, SCREEN_WIDTH - 2 * border, self.headImage.height / 2);
        self.adImage.image = [UIImage imageNamed:@"img_list2111"];
        UITapGestureRecognizer *adImageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adImageTap:)];
        self.adImage.userInteractionEnabled = YES;
        [self.adImage addGestureRecognizer:adImageTap];
        [_footerView addSubview:self.adImage];
        _footerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.headImage.height / 2 + 2*border);
    }return _footerView;
}

- (UIView *)bottomBarView{
    if (!_bottomBarView) {
        int collectBtnW = 50;
        _bottomBarView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - bottomBarH, SCREEN_HEIGHT, bottomBarH)];
        _bottomBarView.backgroundColor = [UIColor orangeColor];
        self.collectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, collectBtnW, _bottomBarView.height)];
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
        [self.collectBtn addTarget:self action:@selector(collectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
        CGFloat offset = 40.0f;
        self.collectBtn.titleEdgeInsets = UIEdgeInsetsMake(-15, -self.collectBtn.imageView.frame.size.width, -self.collectBtn.imageView.frame.size.height-offset/2, 0);
        self.collectBtn.imageEdgeInsets = UIEdgeInsetsMake(-self.collectBtn.titleLabel.intrinsicContentSize.height +5, -15, 0, -self.collectBtn.titleLabel.intrinsicContentSize.width);
        [self initButton:self.collectBtn];
        self.collectBtn.backgroundColor = [UIColor whiteColor];
        self.collectBtn.adjustsImageWhenHighlighted = NO;
        [_bottomBarView addSubview:self.collectBtn];
        
        self.serviceBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.collectBtn.right, 0, self.collectBtn.width, self.collectBtn.height)];
        [self.serviceBtn setImage:[UIImage imageNamed:@"icon_kefu"] forState:UIControlStateNormal];
        [self.serviceBtn addTarget:self action:@selector(serviceBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.serviceBtn setTitle:@"联系客服" forState:UIControlStateNormal];
        self.serviceBtn.backgroundColor = [UIColor yellowColor];
        
        self.serviceBtn.titleEdgeInsets = UIEdgeInsetsMake(-15, -self.serviceBtn.imageView.frame.size.width, -self.serviceBtn.imageView.frame.size.height-offset/2, 0);
        self.serviceBtn.imageEdgeInsets = UIEdgeInsetsMake(-self.serviceBtn.titleLabel.intrinsicContentSize.height + 8, -30, 0, -self.serviceBtn.titleLabel.intrinsicContentSize.width);
        [self initButton:self.serviceBtn];
        self.serviceBtn.backgroundColor = [UIColor whiteColor];
        [_bottomBarView addSubview:self.serviceBtn];
        
        self.addTravelBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.serviceBtn.right, 0, SCREEN_WIDTH - self.serviceBtn.right, self.collectBtn.height)];
        [self.addTravelBtn setTitle:@"加入行程" forState:UIControlStateNormal];
        [self.addTravelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.addTravelBtn addTarget:self action:@selector(addTravelBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self.addTravelBtn setBackgroundColor:getColor(@"ffbb02")];
        self.addTravelBtn.titleLabel.font = DEF_FontSize_16;
        self.addTravelBtn.adjustsImageWhenHighlighted = NO;
        [_bottomBarView addSubview:self.addTravelBtn];
        
    }return _bottomBarView;
}

-(void)initButton:(UIButton*)btn{
    btn.titleLabel.font = DEF_FontSize_10;
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.backgroundColor = [UIColor whiteColor];
}

- (void)setTravelInforModel:(TravelInforModel *)travelInforModel{
    _travelInforModel = travelInforModel;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:self.travelInforModel.pic]];
    self.inforTitleLab.text = self.travelInforModel.title;
    self.priceLab.text = [NSString stringWithFormat:@"%@元", self.travelInforModel.price];
    self.starsControl.score = [self.travelInforModel.star floatValue];
    self.scoreLab.text = [NSString stringWithFormat:@"%@分", self.travelInforModel.level];
    self.commentsLab.text = [NSString stringWithFormat:@"(%@条评价)", self.travelInforModel.comments];
    self.locationLab.text = self.travelInforModel.address;
    if ([self.travelInforModel.is_collect isEqualToString:@"已收藏"]) {
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
    }
    if ([self.travelInforModel.is_collect isEqualToString:@"未收藏"]) {
        [self.collectBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
    }
    [self.videoImage sd_setImageWithURL:[NSURL URLWithString:self.travelInforModel.video_pic]];
    NSString *urlContent = self.travelInforModel.content;
    [self.moreInforWeb loadHTMLString:urlContent baseURL:nil];
    self.comments = [self.travelInforModel.comments intValue];
    if ([self.travelInforModel.is_collect isEqualToString:@"未收藏"]) {
        self.collectBtn.selected = NO;
    }else{
        self.collectBtn.selected = YES;
    }
}

#pragma mark - action
- (void)phoneBtnClick{
    NSLog(@"打电话");
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"10086"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}
- (void)collectBtnClick:(UIButton *)btn{
    NSLog(@"收藏");
    btn.selected = !btn.selected;
    [self travelInforLikeBtnClick];
}

- (void)adImageTap:(UITapGestureRecognizer *)sender{
//    NSLog(@"广告");
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.adModel.url]];
}

- (void)serviceBtnClick{
    NSLog(@"联系客服");
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"10086"];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

- (void)addTravelBtnClick{
    NSLog(@"加入行程");
    if ([_lastVC isKindOfClass:[HomeViewController class]] || [_lastVC isKindOfClass:[HotViewController class]]) {
        self.travelDays = 1;
        MyJourneyViewController * myJourneyVC = [[MyJourneyViewController alloc] init];
        myJourneyVC.tid = self.tid;
        [self.navigationController pushViewController:myJourneyVC animated:YES];
        return;
    }
    //添加一天行程
    [self addNewJourney];
}

- (void)backClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)videoBtnClick{
    NSLog(@"视频点击");
    NSURL *url = [NSURL URLWithString:self.travelInforModel.video_pic];
    AVPlayer *avPlayer= [AVPlayer playerWithURL:url];
    if (@available(iOS 10.0, *)) {
        avPlayer.automaticallyWaitsToMinimizeStalling = NO;
    }
    AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
    playerViewController.player = avPlayer;
    [[UIViewController getCurrentVC] presentViewController:playerViewController animated:YES completion:nil];
    [playerViewController.player play];
}

- (void)moreInforBtnClick:(UIButton *)sender{
    sender.selected = !sender.selected;
    if (sender.selected) {
        [sender setTitle:@"点击收起" forState:UIControlStateNormal];
        
        [UIView animateWithDuration:0.5 animations:^{
            self.moreInforWeb.frame = CGRectMake(self.videoImage.left, self.videoImage.bottom + border, self.videoImage.width, self.webH);
            self.moreInforBtn.frame = CGRectMake((SCREEN_WIDTH - moreInforBtnW) / 2, self.moreInforWeb.bottom + border, moreInforBtnW, labelH);
            [_headerView addSubview:self.moreInforBtn];
            self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.moreInforBtn.bottom + border);
            [self.tableView reloadData];
        }];
    }
    if (!sender.selected) {
        [sender setTitle:@"更多图文详情" forState:UIControlStateNormal];
        self.moreInforWeb.frame = CGRectMake(self.videoImage.left, self.videoImage.bottom + border, self.videoImage.width, 0);
        self.moreInforBtn.frame = CGRectMake((SCREEN_WIDTH - moreInforBtnW) / 2, self.moreInforWeb.bottom + border, moreInforBtnW, labelH);
        [_headerView addSubview:self.moreInforBtn];
        self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, self.moreInforBtn.bottom + border);
        [self.tableView reloadData];
        
        }
}

- (void)wantCommentBtnClick{
    NSLog(@"立即评价");
    ImmediateEvaluationViewController * wantEvalutionVC = [[ImmediateEvaluationViewController alloc] init];
    wantEvalutionVC.travelID = self.tid;
    [self.navigationController pushViewController:wantEvalutionVC animated:YES];
}

- (void)moreCommentBtnClick{
    NSLog(@"更多评论");
    MoreCommentViewController * moreCommentVC = [[MoreCommentViewController alloc] init];
    moreCommentVC.tid = self.tid;
    [self.navigationController pushViewController:moreCommentVC animated:YES];
}

#pragma mark - 代理
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.customMadeModel.data.count;
    }else if (self.cellModel.data.count >= 2) {
            return 2;
        }else{
            return self.cellModel.data.count;
        }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString * cellID = @"CustomMadeCell";
        [self.tableView registerClass:[CustomMadeCell class] forCellReuseIdentifier:cellID];
        CustomMadeCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        if (!cell) {
            cell = [[CustomMadeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.customModelData = self.customMadeModel.data[indexPath.row];
        cell.reservePay = ^(NSString *customId, NSString *reservePayStr, NSString * tid){
            NSLog(@"customId:%@, reservePayStr:%@",customId ,reservePayStr);
            BookingInformationViewController * vc = [[BookingInformationViewController alloc] init];
            vc.reservationDeposit = reservePayStr;
            vc.activityId = customId;
            vc.totalMoney = self.travelInforModel.price;
            vc.type = @"1";
            vc.tid = tid;
            [self.navigationController pushViewController:vc animated:YES];
        };
        return cell;
    }
    if (indexPath.section == 1) {
        static NSString * cellID = @"VsitorCommentCell";
        [self.tableView registerClass:[VsitorCommentCell class] forCellReuseIdentifier:cellID];
        VsitorCommentCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        if (!cell) {
            cell = [[VsitorCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.cellModelData = self.cellModel.data[indexPath.row];
        return cell;
    }
    else{
        return nil;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 44;
    }else{
        return 60;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * sectionBGView = [[UIView alloc] init];
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = getColor(bgColor);
    [sectionBGView addSubview:lineView];
    UILabel * personalOrderLab = [[UILabel alloc] init];
    personalOrderLab.font = DEF_FontSize_14;
    personalOrderLab.textAlignment = NSTextAlignmentCenter;
    personalOrderLab.frame = CGRectMake(0, 0, SCREEN_WIDTH, 20);
    [sectionBGView addSubview:personalOrderLab];
    sectionBGView.frame = personalOrderLab.frame;
    if (section == 0) {
        personalOrderLab.text = @"私人订制";
    }else{
        personalOrderLab.text = @"游客评价";
    }
    if (self.cellModel.data.count == 0) {
        personalOrderLab.hidden = YES;
    }else{
        personalOrderLab.hidden = NO;
    }
    return sectionBGView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }
    if (section == 1) {
        return sectionH;
    }
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if (section == 0) {
        UIView * nilView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        return nilView;

    }if (section == 1) {
        CGFloat wantCommentBtnW = 80;
        CGFloat wantCommentBtnX = (SCREEN_WIDTH - wantCommentBtnW)/2;
        CGFloat btnH = 30;
        UIView * BGView = [[UIView alloc] init];
        BGView.backgroundColor = [UIColor whiteColor];
        
        self.moreCommentBtn = [[UIButton alloc] init];
        self.moreCommentBtn.backgroundColor = [UIColor whiteColor];
        self.moreCommentBtn.frame = CGRectMake(0, border/2, SCREEN_WIDTH, btnH);
        [self.moreCommentBtn setImage:[UIImage imageNamed:@"icon_in"] forState:UIControlStateNormal];
        [self.moreCommentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.moreCommentBtn.titleLabel.font = DEF_FontSize_14;
        self.moreCommentBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -180);
        self.moreCommentBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
        [self.moreCommentBtn addTarget:self action:@selector(moreCommentBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [BGView addSubview:self.moreCommentBtn];

        self.wantCommentBtn = [[UIButton alloc] init];
        self.wantCommentBtn.frame = CGRectMake(wantCommentBtnX, self.moreCommentBtn.bottom + border, wantCommentBtnW, btnH);
        self.wantCommentBtn.layer.borderColor = [UIColor orangeColor].CGColor;
        self.wantCommentBtn.layer.borderWidth = 1;
        [self.wantCommentBtn setTitle:@"我要评论" forState:UIControlStateNormal];
        self.wantCommentBtn.titleLabel.font = DEF_FontSize_14;
        [self.wantCommentBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self.wantCommentBtn setCornerRadius:8];
        [self.wantCommentBtn addTarget:self action:@selector(wantCommentBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [BGView addSubview:self.wantCommentBtn];
        if (self.comments > 2) {
            self.moreCommentBtn.hidden = NO;
            NSString * num = [NSString stringWithFormat:@"更多%d条评论", self.comments - 2];
            [self.moreCommentBtn setTitle:num forState:UIControlStateNormal];
            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:num];
            // 需要改变的第一个文字的位置
            NSUInteger firstLoc = [[noteStr string] rangeOfString:@"多"].location + 1;
            // 需要改变的最后一个文字的位置
            NSUInteger secondLoc = [[noteStr string] rangeOfString:@"条"].location;
            // 需要改变的区间
            NSRange range = NSMakeRange(firstLoc, secondLoc - firstLoc);
            [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor cyanColor] range:range];
            [noteStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:18] range:range];
            [self.moreCommentBtn.titleLabel setAttributedText:noteStr];
        }else{
            self.moreCommentBtn.hidden = YES;
        }
        return BGView;
    }
    return nil;
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    //修改字体大小 300%
//    [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '250%'" completionHandler:nil];
    WS(ws)
    [webView evaluateJavaScript:@"document.body.offsetHeight;" completionHandler:^(id _Nullable any, NSError * _Nullable error) {
        NSString *heightStr = [NSString stringWithFormat:@"%@",any];
        ws.webH = [heightStr intValue];
    }];

}

@end
